<?php

/**
 * Name: 生产事故验证层
 * User: Silent
 * Date: 2025-09-20
 * Time: 22:42:44
 */

namespace App\Http\Requests\Safety;

use Illuminate\Foundation\Http\FormRequest;

class ProductionAccidentRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        $rules = [
            'device_name'    => 'required|string|max:255',
            'accident_at'    => 'required',
            'description'    => 'required|string',
            'cause_analysis' => 'required|string',
            'solution'       => 'required|string',
            'notes'          => 'required|string',
        ];

        $action = optional($this->route())->getActionMethod();
        if ($action === 'update') {
            $rules['id'] = 'required|integer';
        }

        return $rules;
    }

    public function messages(): array
    {
        return [
            'device_name.required'    => '设备名称不能为空',
            'accident_at.required'    => '事故发生时间不能为空',
            'description.required'    => '事故现象描述不能为空',
            'cause_analysis.required' => '原因分析不能为空',
            'solution.required'       => '解决方案不能为空',
            'notes.required'          => '备注不能为空',
            'id.required'             => 'ID不能为空',
            'id.integer'              => 'ID必须为整数',
        ];
    }
}
